/**
 * 将输入中行长度超过规定长度的行折叠为多行输出
 */

#include <stdio.h>

#define MAXLINE 1000
#define FOLDLENGTH 70

int getlines(char s[], int lim);

int main() {
    int c, length;
    char line[MAXLINE];

    while ((length = getlines(line, MAXLINE)) > 0) {
        if (length <= FOLDLENGTH) {
            printf("%s", line);
        } else {
            int i, fold;
            i = fold = 0;
            while (i < length) {
                if (line[i] == ' ' || line[i] == '\t') fold = i;
                if (!(i % FOLDLENGTH)) line[fold] = '\n';
                i++;
            }
            printf("%s", line);
        }
    }

    return 0;
}



// 从输出中获取内容凑成一行直到遇到换行符或者达到lim限制长度
int getlines(char s[], int lim) {
    int i, c;
    for( i = 0; i < lim-1 && (c = getchar()) != EOF && c != '\n'; i++) {
        s[i] = c;
    }
    if (c == '\n') {
        s[i] = '\n';
        i++;
    }
    s[i] = '\0';

    return i;
}

